﻿<?php

function str_replace_once($needle, $replace, $haystack) { 

// Looks for the first occurence of $needle in $haystack 

// and replaces it with $replace. 

$pos = strpos($haystack, $needle); 

if ($pos === false) { 

return $haystack; 

} 

return substr_replace($haystack, $replace, $pos, strlen($needle)); 

} 
function get_between($input, $start, $end) {

  $substr = substr($input, strlen($start)+strpos($input, $start),

 (strlen($input) - strpos($input, $end))*(-1));

  return $substr;

}

file_put_contents("wd.htm",'
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'.$_GET["word"]);
$url = 'http://m.baidu.com'.$_SERVER["REQUEST_URI"];
$html = file_get_contents($url);

$html = str_replace('class="logo" href="','class="logo" href="../baidu',$html);
$ewai = file_get_contents('ewai.txt');
$word = $_GET['word'];
$ewai = str_replace('<em>彩虹</em>','<em>'.$word.'</em>',$ewai);

if(strstr($word,'吧') == '')$wordb=$word.'吧';
$ewai = str_replace('<em>青年文摘吧</em>','<em>'.$wordb.'</em>',$ewai);

$ewai = str_replace('tblj','http://tieba.baidu.com/f?kw='.$wordb,$ewai);

$html = str_replace_once('<div id="page-rel',$ewai.'<div id="page-rel',$html);

$bj = file_get_contents('bj.txt');
$bj = str_replace('彩虹',$word,$bj);
$html = str_replace('</head><body>',$bj,$html);




echo $html;
?>